package com.zpb.admin.controller;

import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.dto.TagDto;
import com.zpb.framework.domain.enums.ResultCodeEnum;
import com.zpb.framework.domain.vo.PageVo;
import com.zpb.framework.domain.vo.TagSimpleVo;
import com.zpb.framework.domain.vo.TagVo;
import com.zpb.framework.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/17
 */
@RestController
@RequestMapping("/content/tag")
public class SysTagController {
    @Autowired
    private TagService tagService;
    @GetMapping("/list")
    public ApiResult<PageVo> getTagList(@RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        TagDto tagDto){
        return tagService.list(pageNum,pageSize,tagDto);
    }
    @PostMapping
    public ApiResult addTag(@RequestBody TagDto tagDto){
        if (ObjectUtils.isEmpty(tagDto.getRemark())||ObjectUtils.isEmpty(tagDto.getName())){
            return ApiResult.failure(ResultCodeEnum.MISS_PARAM);
        }
        return tagService.addTag(tagDto);
    }
    @DeleteMapping("/{id}")
    public ApiResult deleteTag(@PathVariable Long id){
        if (ObjectUtils.isEmpty(id)){
            return ApiResult.failure(ResultCodeEnum.MISS_PARAM);
        }
        return tagService.delTag(id);
    }
    @GetMapping("/{id}")
    public ApiResult<TagVo> getTag(@PathVariable Long id){
        if (ObjectUtils.isEmpty(id)){
            return ApiResult.failure(ResultCodeEnum.MISS_PARAM);
        }
        return tagService.getTag(id);
    }
    @PutMapping
    public ApiResult updateTag(@RequestBody TagDto tagDto){
        if (ObjectUtils.isEmpty(tagDto.getId())){
            return ApiResult.failure(ResultCodeEnum.NO_ID);
        }
        return tagService.update(tagDto);
    }
    @GetMapping("/listAllTag")
    public ApiResult<List<TagSimpleVo>> getAllTag(){
        return tagService.getAll();
    }

}
